package cn.szzsi.business.interceptor;

import cn.szzsi.common.util.CommonUtil;
import cn.szzsi.model.Member;
import cn.szzsi.model.OperateLogs;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;

/**
 * Created by yuanzheng on 2016/12/6.
 */
public class OperationLogsInterceptor implements Interceptor {
    public void intercept(Invocation ai) {
        Controller c = ai.getController();
        String loginMemberId = c.getAttr("userId");//获取当前登录用户
        String requestUrl=c.getRequest().getRequestURI();//访问路径
        if(StrKit.notBlank(loginMemberId) && (requestUrl.contains("/shop/") || requestUrl.contains("/member"))){
            Member member=Member.dao.findById(loginMemberId);
            String shopId=member.getStr("shopId");//店铺Id
            String b_shoprank=member.getStr("b_shoprank");//店铺管理员类别:super-超级管理员,shopid-普通管理员
            String username=member.getStr("username");//用户名
            String uid="";
            if(CommonUtil.PLATFORM_BUSINESS.equals(shopId)){
                if("super".equals(b_shoprank)){//超级管理员
                    uid=loginMemberId;
                }else{//普通管理员
                    uid=b_shoprank;
                }
                if(requestUrl.contains("/member/")){//管理员登录
                    OperateLogs.dao.saveLog(loginMemberId,username,"登录",uid,"0");
                }else if(requestUrl.contains("siteconfig/update")){//
                    OperateLogs.dao.saveLog(loginMemberId,username,"更新店铺参数设置",uid,"1");
                }else if(requestUrl.contains("template/template")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"更换模板",uid,"1");
                }else if(requestUrl.contains("productCategroy/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加商品分类",uid,"1");
                }else if(requestUrl.contains("productCategroy/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"更新商品分类",uid,"1");
                }else if (requestUrl.contains("products/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加商品",uid,"1");
                }else if(requestUrl.contains("products/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑商品",uid,"1");
                }else if(requestUrl.contains("brand/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加品牌",uid,"1");
                }else if(requestUrl.contains("brand/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑品牌",uid,"1");
                }else if(requestUrl.contains("articles/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加文章",uid,"1");
                }else if(requestUrl.contains("articles/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑文章",uid,"1");
                }else if(requestUrl.contains("articlecategory/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加文章分类",uid,"1");
                }else if(requestUrl.contains("articlecategory/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑文章分类",uid,"1");
                }else if(requestUrl.contains("navigation/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加导航管理",uid,"1");
                }else if(requestUrl.contains("navigation/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑导航管理",uid,"1");
                }else if(requestUrl.contains("friendLink/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加友情链接",uid,"1");
                }else if(requestUrl.contains("friendLink/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑友情链接",uid,"1");
                }else if(requestUrl.contains("paymentConfig/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加支付方式",uid,"1");
                }else if(requestUrl.contains("paymentConfig/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑支付方式",uid,"1");
                }else if(requestUrl.contains("paymentConfig/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加配送方式",uid,"1");
                }else if(requestUrl.contains("deliveryType/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑配送方式",uid,"1");
                }else if(requestUrl.contains("orderManage/view")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"查看订单详情",uid,"1");
                }else if(requestUrl.contains("orderManage/shipping")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"订单发货",uid,"1");
                }else if(requestUrl.contains("orderManage/payment")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"订单支付",uid,"1");
                }else if(requestUrl.contains("orderManage/completed")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"订单完成",uid,"1");
                }else if(requestUrl.contains("orderManage/invalid")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"订单作废",uid,"1");
                }else if(requestUrl.contains("orderManage/refund")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"订单退款",uid,"1");
                }else if(requestUrl.contains("orderManage/reship")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"订单退货",uid,"1");
                }else if(requestUrl.contains("adManage/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加广告管理",uid,"1");
                }else if(requestUrl.contains("adManage/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑广告管理",uid,"1");
                }else if(requestUrl.contains("user/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加管理员",uid,"1");
                }else if(requestUrl.contains("user/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑管理员",uid,"1");
                }else if(requestUrl.contains("role/save")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"添加角色",uid,"1");
                }else if(requestUrl.contains("role/update")){
                    OperateLogs.dao.saveLog(loginMemberId,username,"编辑角色",uid,"1");
                }

            }

        }
        ai.invoke();
    }
}
